<template>
	<view>
		<cu-custom bgColor="bg-gradual-fff" isBack="true">
			<block slot="content">商品评价</block> 
		</cu-custom>
		<loading-view v-if="showLoading"></loading-view>
		<view v-show="!showLoading">
			<view class="viewbox"></view>
			<view class="goods_info_b_b">
				<EvaluateList :list="commentList"></EvaluateList>
			</view>
			<loading-footer :status="status" :slot-empty="true">
				<view slot="empty" class="column-center" style="padding-top: 200rpx">
					<image class="img-null" src="/static/goods_null.png"></image>
					<text class="lighter">暂无评论</text>
				</view>
			</loading-footer>
		</view>
	</view>
</template>
<script>
import request from '@/common/request.js';	
import {
	loadingType,
	trottle
} from '@/utils/type';
export default {
	data() {
		return {
			showLoading:true,
			uid:0,
			commentList:[],
			status: loadingType.LOADING,
			page: 1,
			limit:8,
		}
	},
	onLoad: function (options) {
		this.uid=uni.getStorageSync('uid');
		this.id=options.id;
		this.onRefresh();
	},
	onShow(){
	},
	onReachBottom: function() {
		this.getCommentListFun();
	},
	mounted() {
		//this.home_post();
	},
	methods: {
		init(option) {
			let {
				id
			} = option;
			this.id = id;
			this.getCommentListFun();
		},
		onRefresh() {
			this.page = 1
			this.commentList = []
			this.status = loadingType.LOADING
			this.$nextTick(() => {
				this.getCommentListFun();
			});
		},
		async getCommentListFun() {
			let {
				page,
				limit,
				status,
				commentList,
			} = this;
			if (status == loadingType.FINISHED) return;
			const paramsList = {
				page: page,
				limit:limit,
				uid:this.uid,
				id:this.id
			}
			let optsList = {
				url: 'comment-lists',
				method: 'get'
			};
			request.httpRequest(optsList, paramsList).then(res => {
				console.log(res);
				if(res.data.code == 200){
					if(page == 1) commentList = []
					let {
						list,
						more
					} = res.data.data
					this.commentList.push(...list)
					this.page = ++this.page
					if (!more) {
						this.status = loadingType.FINISHED
					}
					if (this.commentList.length <= 0) {
						this.status = loadingType.EMPTY
					}
				} else {
					this.status = loadingType.ERROR
				}
				this.showLoading=false;
			});
		}
	}
}
</script>

<style  lang="scss" scoped>
	.goods_info_b_b{
		background-color: #fff;
		padding: 20rpx 24rpx;
		overflow: hidden;
		width: 750rpx;
	}
</style>
